var http = require('http');
var fs = require('fs');
var url = require('url');

var server = http.createServer(callback);
server.listen(3000,'localhost');
console.log("server is runing localhost:3000");

function callback(request,response){
    var pathName = url.parse(request.url).pathname;
    if(pathName == "/favicon.ico"){ 
        return; 
    }
    console.log("Request for " + pathName.substr(1) + " received.");
    fs.readFile(pathName.substr(1),function(err,data){
        if(err){
            console.log(err);
            response.writeHead(404,{'Content-Type':'text/html'});
        }else{
            response.writeHead(200,{'Content_type':'text/html'});
            response.write(data.toString());
        }
        response.end();
    })
    
    
}